package com.app;

import com.common.Variable;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;


public class QuestionBank {


    /**
     * @param questionby 为进入试题入口
     */
    public static void drive(By questionby) {

        System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("http://" + Variable.IP + "/?token=" + Variable.TOKEN + "#/home");


        //精选题库
        driver.findElement(By.className("two-left")).click();
        waitTime(3000);
        //试题一
        driver.findElement(questionby).click();
        waitTime(3000);

        //第一题
        testProblem(1, driver);

        for (int i = 2; i <= 100; i++) {

            waitTime(3000);
            testProblem(i, driver);
        }
        //driver.close();
    }


    private static void testProblem(int i, WebDriver driver) {


        //帮助
        try {
            driver.findElement(By.className("help-btn")).click();
            try {
                driver.findElement(By.xpath("//*[@class='video-div']/button[1]/span[1]")).click();
                waitTime(5000);
            } catch (Exception e) {
                System.out.println("第" + i + "题视频错误");
            }
            driver.findElement(By.className("help-btn")).click();
        } catch (Exception e) {
            System.out.println("第" + i + "题视频没有");
        }

        waitTime(3000);
        //选择A
        driver.findElement(By.className("ion-ios-a")).click();
        waitTime(3000);

        //选择A
        try {
            String context = driver.findElement(By.className("help-msg")).getText();
            //System.out.println(context);
            //if (context.contains("错")) {
            System.out.println("第" + i + "题答案应该为错");


            //下一题
            driver.findElement(By.className("ion-ios-arrow-forward")).click();
        } catch (Exception e) {
            System.out.println("第" + i + "题答案应该为对");
        }


        waitTime(3000);
    }

    private static void waitTime(int time) {

        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
